package com.chenxin.interact.api;

import com.chenxin.common.annotation.InterfaceLogs;
import com.chenxin.common.constant.WmsConstants;
import com.chenxin.common.core.controller.BaseController;
import com.chenxin.common.core.domain.AjaxResult;
import com.chenxin.common.core.domain.ProcResult;
import com.chenxin.common.utils.StringUtils;
import com.chenxin.interact.domain.dto.IqcIncomingResponseDTO;
import com.chenxin.interact.domain.dto.IqcOutResponseDTO;
import com.chenxin.interact.domain.dto.IqcOverdueResponseDTO;
import com.chenxin.interact.process.IQmsInteractProcess;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("qms/interact")
public class QmsAPI extends BaseController {
    @Autowired
    private IQmsInteractProcess qmsProcess;

    @PostMapping("/iqcIncomingResponse")
    public AjaxResult iqcIncomingResponse(@RequestBody IqcIncomingResponseDTO dto) {
        log.info("来料检验回传：{}", dto);
        if (StringUtils.isEmpty(dto.getEbeln())) {
            return error("PO单号【EBELN】不能为空");
        }
        return success("成功接收来料检验回传");
    }

    @InterfaceLogs(name = "超期复检回传")
    @PostMapping("/iqcOverdueResponse")
    public AjaxResult iqcOverdueResponse(@RequestBody IqcOverdueResponseDTO dto) {
        ProcResult result = qmsProcess.procQmsOverdue(dto);
        if (WmsConstants.PROC_SUCCESS.equals(result.getCode())) {
            return success(result.getMessage());
        } else {
            return error(result.getMessage());
        }
    }

    @InterfaceLogs(name = "MES出库检验回传")
    @PostMapping("/iqcOutResponse")
    public AjaxResult iqcOutResponse(@RequestBody IqcOutResponseDTO dto) {
        return success("成功接收出库检验回传数据");
    }
}
